<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>企业简介</title>
    <link rel="stylesheet" href="../css/common.css">
    <link rel="stylesheet" href="../css/style_zj.css">
    <link rel="stylesheet" href="../layui/css/layui.css">
    <link rel="stylesheet" href="../fonts/iconfont.css">
</head>
<body>
<!--<div id="header_01_html">
    <iframe id="header_01" src="head_01.html" frameborder="0"></iframe>
</div>-->
<div class="content-box">
    <!--<div id="left_tab_html">
        <iframe id="left_tab" src="left_tab.html?x=3&y=2" frameborder="0"></iframe>
    </div>-->
    <div class="right-box layui-form">
        <div class="friend-tips">
            <div class="title-box"><i class="icon-sty"></i><b class="title-tip">温馨提示</b></div>
            <div class="info-list">1、以下为发布企业简介栏目、“公司介绍图片”发布，可发文字介绍及插入图片等！</div>
            <div class="info-list">2、关注左侧“企业栏目设置”，可方便企业增加各种其它展示栏目，如“企业荣誉”、“厂房设备”等</div>
        </div>
        <div class="content-admin">

            <div class="title-toggle">
                <div class="item active">企业简介</div>
            </div>
            <div>
                <div class="input-box1">
                    <div class="li clearfix">
                        <div class="left-k"><span class="col-ff4">*</span><span class="text-sty1">公司介绍图片</span></div>
                    </div>
                    <div class="li clearfix">
                        <!--<div class="left-k"><span class="col-ff4"></span><span class="text-sty1"></span></div>-->
                        <div class="file-img">
                            <div class="box-file">
                                <img src="../img/file1.png" alt="" class="upload_btn">
                            </div>
                        </div>
                    </div>
                    <div class="li clearfix">
                        <div class="left-k"><span class="col-ff4">*</span><span class="text-sty1">公司文字介绍</span></div>
                    </div>
                    <div class="li clearfix">
                        <div class="right-v wid-820">
                            <textarea id="demo" style="display: none;"></textarea>
                        </div>
                    </div>
                    <div class="">
                        <span class="release-btn1 js-submitBtn">确认修改</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!--<div>
    <iframe src="footer-record.html" style="width: 100%;border: none;height:60px;"></iframe>
</div>-->
<script src="../js/config.js"></script>
<script>
    var isAdd = '';
    var picUrl = '';
    var content = '';
    var edit = '';
    var layedit = '';
    var id = '';

    get_ajax("cms/getAllNewPage", {storeId:localStorage.getItem('storeId'),type:2,offset:1,limit:10}, function (data) {
        if(data.length==0){isAdd = true}else{isAdd = false}
        console.log(data[0]);
        $('#demo').val(data[0].content);
        id = data[0].id;
        var picArr = data[0].picUrl.split(',');
        picArr.forEach(function(item){
            var el ='<div class="box-file" data-picUrl="'+item+'">'
                +'<span class="del-png icon_close"></span>'
                +'<img src="'+imgBaseUrl+item+'" alt="" class="upload_btn">'
                +'</div>'
            $('.file-img').append(el);
        })

    })
    setTimeout(function(){
        layui.use('layedit', function(){
            layedit = layui.layedit;
            layedit.build('demo'); //建立编辑器
            layedit.set({
                uploadImage: {
                    url: baseUrl + '/file/layeditUplode?token=' + Token,
                    type: "post"
                }
            });
            edit = layedit.build('demo');
        });
    },200)

    //图片上传
    layui.use(['upload'], function () {
        var $ = layui.jquery, upload = layui.upload;
        //普通图片上传

        var uploadInst = upload.render({
            elem: '.upload_btn'
            ,multiple:true
            , url: baseUrl + '/file/upload?token=' + Token
            , before: function (obj) {
                loading = layer.load(1, {
                    shade: [0.1, '#fff'] //0.1透明度的白色背景
                });
            }
            , done: function (res, index) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg.msg('上传失败');
                } else {
                    if($('.file-img .box-file').length>6){
                        layer.close(loading);
                        layer.msg('最多上传6张图片');
                        return false;
                    }

                    var data = res.data;
                    var el ='<div class="box-file" data-picUrl="'+data.address+'">'
                        +'<span class="del-png">i</span>'
                        +'<img src="'+imgBaseUrl+data.address+'" alt="" class="upload_btn">'
                        +'</div>'
                    $('.file-img').append(el);
                    layer.close(loading);
                    console.log('上传成功！')
                }

            }
            , error: function () {

            }
        });
    })
    $(document).on('click','.del-png',function(){//    del-png
        $(this).parents('.box-file').remove();
    })


    $(document).on('click','.js-submitBtn',function(){   //提交
        content = layedit.getContent(edit)
        var pngStr = '';
        $('.box-file').each(function(index){
            if(index>0){
                pngStr += $(this).attr('data-picurl')+','
            }
        })
        picUrl = pngStr.slice(0,pngStr.length-1);
        if(isAdd){
            get_ajax("cms/saveNewInfo", {title:'',content:content,picUrl:picUrl,type:2}, function (data) {
                console.log(data);
                layer.msg('新增成功！');
            })
        }else{
            get_ajax("cms/editNewInfo", {title:'',id:id,content:content,picUrl:picUrl,type:2}, function (data) {
                console.log(data);
                layer.msg('编辑成功！');
            })

        }
    })
</script>
</body>
</html>